<title>订单分析数据</title>
<link rel="stylesheet" href="/static/public/vendor/select2/select2.css">

<script src="/static/public/vendor/select2/select2.min.js" data-name="select2"></script>
<script src="/static/public/vendor/select2/i18n/zh-CN.min.js" data-deps="select2"></script>
<div class="page-content">
    <div class="collapse in" id="collapseFilter" aria-expanded="true">
        <div class="panel">
            <div class="panel-body">

                <form class="form-inline" id="projectForm">
                    <div class="form-group">
                        <select id="batchId" onchange="change()" class="form-control" name="url" data-plugin="select2" style="width: 200px">
                            <option value="">项目名称</option>
                            #foreach( $prj in $prjList )
                            <option value="${prj.id}">${prj.name}</option>
                            #end
                        </select>
                    </div>
                    <div class="form-group">
                        <span class="btn btn-success" onclick="query()"><i class="icon fa-search"></i> 查找</span>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="panel">
        <div class="panel-body">
            <table class="table table-bordered table-hover dataTable table-striped width-full text-nowrap"
                   id="dataTableExample">
                <thead>
                <tr>
                    <th>项目</th>
                    <th>客户</th>
                    <th>订单数量</th>
                    <th>物料种类</th>
                    <th>配送中心</th>
                    <th>工厂</th>
                    <th>订单回收量</th>
                    <th>导入日期</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>

<script src="/static/public/vendor/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript">
    var $table = null;
    function openDialog() {
        Dialog.open("上传订单分析数据", "/file/uploadFile", {fileType: "19"});
    }
    function query() {
        $table.ajax.reload();
    }
    function reloadData() {
        $table.ajax.reload();
    }
    function change() {
        $table.ajax.reload();
    }
    $(function () {
        $table = $('#dataTableExample').DataTable($.po('dataTable', {
            "processing": true,
            "serverSide": true,
            "ordering": false,
            "columns": [
                {"data": "batchName", "defaultContent": ""},
                {"data": "name"},
                {"data": "orderPositive"},
                {"data": "type"},
                {"data": "distributionCenter"},
                {"data": "factory"},
                {"data": "orderRecovery"},
                {"data": "createTime"},
            ],
            "columnDefs": [{
                "render": function (data, type, row) {
                    return Date.format(new Date(data), "yyyy-MM-dd hh:mm:ss");
                },
                "targets": 7
            },
                {"render": function (data, type, row) {
                    if(data==null){
                        return "没上传数据";
                    }else {
                        return data;
                    }
                }, "targets": 3},
                {"render": function (data, type, row) {
                    if(data==null){
                        return "没上传数据";
                    }else {
                        return data;
                    }
                }, "targets": 6}],
            "dom": '<"dt-dom-toolbar">rt<"bottom"pi>',
            "fnServerData": function (sSource, aoData, fnCallback) {
                var params = [
                    {name: "size", value: aoData[4].value}, {
                        name: "current", value: aoData[3].value / aoData[4].value + 1
                    }];
                var batchId = $("#batchId").val();
                if (batchId) {
                    params.push({name: 'batchId', value: batchId});
                }
                $.ajax({
                    "dataType": 'json',
                    "type": "post",
                    "data": params,
                    "url": "/network/city/order/getData",
                    "success": fnCallback
                });
            }
        }));

        $("div.dt-dom-toolbar").append('<a class="btn btn-success margin-bottom-15"  href="#" onclick="openDialog()"><i class="icon wb-upload" aria-hidden="true"></i>上传文件</a>');
        $("div.dt-dom-toolbar").append('<a  class="btn btn-success margin-bottom-15 margin-left-15" href="/file/downLoad?file_name=cityorder&file=订单分析数据"><i class="icon wb-download" aria-hidden="true"></i>下载模板</a>');
    })
</script>